package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 仅用于测试业务逻辑-将指定专辑上架到索引库
     *
     * @param albumId
     * @return
     */
    @Operation(summary = "仅用于测试业务逻辑-将指定专辑上架到索引库")
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }


    /**
     * 仅用于测试业务逻辑-将指定专辑删除
     * @param albumId
     * @return
     */
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }


    /**
     * 专辑站内检索
     * @param albumIndexQuery 查询条件：关键字，分类，标签  分页参数 排序字段
     * @return
     */
    @Operation(summary = "专辑站内检索")
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }


    /**
     * 查询指定1级分类下置顶7个三级分类下热门专辑前6
     * @param category1Id
     * @return
     */
    @Operation(summary = "查询指定1级分类下置顶7个三级分类下热门专辑前6")
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> getTopCategoryAlbumList(@PathVariable Long category1Id){
        List<Map<String, Object>> list = searchService.getTopCategoryAlbumList(category1Id);
        return Result.ok(list);
    }


    /**
     * 根据用户正在录入文本进行自动联想
     * @param keyword 任意字符
     * @return 用于自动补全文本列表
     */
    @Operation(summary = "根据用户正在录入文本进行自动联想")
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword){
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }


    /**
     * 更新Redis所有1级分类不同排序TOP10专辑
     * @return
     */
    @Operation(summary = "更新Redis所有1级分类不同排序TOP10专辑")
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }


    /**
     * 根据分类以及排序方式获取top10专辑列表
     * @param category1Id
     * @param dimension
     * @return
     */
    @Operation(summary = "根据分类以及排序方式获取top10专辑列表")
    @GetMapping("albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> getRankingList(@PathVariable Long category1Id, @PathVariable String dimension){
        List<AlbumInfoIndex> list = searchService.getRankingList(category1Id, dimension);
        return Result.ok(list);
    }
}

